package cn.jane.rpc.test.util;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NameServiceUtil {

    private static final Logger log = LoggerFactory.getLogger(NameServiceUtil.class);

    /**
     * 获取 NameService 的 URI，如果获取失败，则直接退出
     */
    public static URI getNameServiceURI() {
        try {
            URL rpcAccessPointURL = NameServiceUtil.class.getClassLoader().getResource("NameService");
            if (rpcAccessPointURL == null) {
                log.error("can not find file \"NameService\"");
                System.exit(1);
            }

            return rpcAccessPointURL.toURI();
        } catch (URISyntaxException e) {
            log.error("parse rpcAccessPointURI error", e);
            System.exit(1);
        }
        return null;
    }
}
